package com.share.user.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.share.user.properties.WxProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WxConfig {

    @Autowired
    private WxProperties wxProperties;

    //微信api提供的bean，可快速发起http请求获取openid
    @Bean
    public WxMaService wxMaService(){

        //其中封装好了通过httpclient向微信第三方接口发起请求
        WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();

        //设置好两个参数后，将配置传入wxMaService bean
        wxMaDefaultConfig.setAppid(wxProperties.getAppId());
        wxMaDefaultConfig.setSecret(wxProperties.getSecret());

        WxMaService wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(wxMaDefaultConfig);

        return wxMaService;
    }

}
